
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/02/2011 15:09:54
-- Generated from EDMX file: C:\Users\Kasper\Dropbox\Skole kasper\5. semester\Hovedopgave\Kode\Task Management\TaskManagement\DataAccess\TaskModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Tasks];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_TaskEntityTaskEntity_TaskEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TaskEntityTaskEntity] DROP CONSTRAINT [FK_TaskEntityTaskEntity_TaskEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_TaskEntityTaskEntity_TaskEntity1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TaskEntityTaskEntity] DROP CONSTRAINT [FK_TaskEntityTaskEntity_TaskEntity1];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectEntityWorkflowEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkflowEntitySet] DROP CONSTRAINT [FK_ProjectEntityWorkflowEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkflowEntityTaskEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TaskEntitySet] DROP CONSTRAINT [FK_WorkflowEntityTaskEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_EmployeeEntityTaskEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TaskEntitySet] DROP CONSTRAINT [FK_EmployeeEntityTaskEntity];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[ProjectEntitySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectEntitySet];
GO
IF OBJECT_ID(N'[dbo].[WorkflowEntitySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WorkflowEntitySet];
GO
IF OBJECT_ID(N'[dbo].[EmployeeEntitySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EmployeeEntitySet];
GO
IF OBJECT_ID(N'[dbo].[TaskEntitySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TaskEntitySet];
GO
IF OBJECT_ID(N'[dbo].[TaskEntityTaskEntity]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TaskEntityTaskEntity];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'ProjectEntitySet'
CREATE TABLE [dbo].[ProjectEntitySet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [StartDate] datetime  NOT NULL
);
GO

-- Creating table 'WorkflowEntitySet'
CREATE TABLE [dbo].[WorkflowEntitySet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [StartDate] datetime  NOT NULL,
    [ProjectEntityId] int  NULL
);
GO

-- Creating table 'EmployeeEntitySet'
CREATE TABLE [dbo].[EmployeeEntitySet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [FirstName] nvarchar(max)  NOT NULL,
    [LastName] nvarchar(max)  NOT NULL,
    [PhoneNumber] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [EmployedAs] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'TaskEntitySet'
CREATE TABLE [dbo].[TaskEntitySet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Delivery] nvarchar(max)  NOT NULL,
    [Tag] nvarchar(max)  NOT NULL,
    [Account] nvarchar(max)  NOT NULL,
    [Status] nvarchar(max)  NOT NULL,
    [Date] datetime  NOT NULL,
    [Estimate] int  NOT NULL,
    [TimeSpent] int  NOT NULL,
    [WorkflowEntityId] int  NULL,
    [EmployeeEntityId] int  NULL
);
GO

-- Creating table 'TaskEntityTaskEntity'
CREATE TABLE [dbo].[TaskEntityTaskEntity] (
    [Predecessors_Id] int  NOT NULL,
    [Successors_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'ProjectEntitySet'
ALTER TABLE [dbo].[ProjectEntitySet]
ADD CONSTRAINT [PK_ProjectEntitySet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'WorkflowEntitySet'
ALTER TABLE [dbo].[WorkflowEntitySet]
ADD CONSTRAINT [PK_WorkflowEntitySet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EmployeeEntitySet'
ALTER TABLE [dbo].[EmployeeEntitySet]
ADD CONSTRAINT [PK_EmployeeEntitySet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TaskEntitySet'
ALTER TABLE [dbo].[TaskEntitySet]
ADD CONSTRAINT [PK_TaskEntitySet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Predecessors_Id], [Successors_Id] in table 'TaskEntityTaskEntity'
ALTER TABLE [dbo].[TaskEntityTaskEntity]
ADD CONSTRAINT [PK_TaskEntityTaskEntity]
    PRIMARY KEY NONCLUSTERED ([Predecessors_Id], [Successors_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Predecessors_Id] in table 'TaskEntityTaskEntity'
ALTER TABLE [dbo].[TaskEntityTaskEntity]
ADD CONSTRAINT [FK_TaskEntityTaskEntity_TaskEntity]
    FOREIGN KEY ([Predecessors_Id])
    REFERENCES [dbo].[TaskEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Successors_Id] in table 'TaskEntityTaskEntity'
ALTER TABLE [dbo].[TaskEntityTaskEntity]
ADD CONSTRAINT [FK_TaskEntityTaskEntity_TaskEntity1]
    FOREIGN KEY ([Successors_Id])
    REFERENCES [dbo].[TaskEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TaskEntityTaskEntity_TaskEntity1'
CREATE INDEX [IX_FK_TaskEntityTaskEntity_TaskEntity1]
ON [dbo].[TaskEntityTaskEntity]
    ([Successors_Id]);
GO

-- Creating foreign key on [ProjectEntityId] in table 'WorkflowEntitySet'
ALTER TABLE [dbo].[WorkflowEntitySet]
ADD CONSTRAINT [FK_ProjectEntityWorkflowEntity]
    FOREIGN KEY ([ProjectEntityId])
    REFERENCES [dbo].[ProjectEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectEntityWorkflowEntity'
CREATE INDEX [IX_FK_ProjectEntityWorkflowEntity]
ON [dbo].[WorkflowEntitySet]
    ([ProjectEntityId]);
GO

-- Creating foreign key on [WorkflowEntityId] in table 'TaskEntitySet'
ALTER TABLE [dbo].[TaskEntitySet]
ADD CONSTRAINT [FK_WorkflowEntityTaskEntity]
    FOREIGN KEY ([WorkflowEntityId])
    REFERENCES [dbo].[WorkflowEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WorkflowEntityTaskEntity'
CREATE INDEX [IX_FK_WorkflowEntityTaskEntity]
ON [dbo].[TaskEntitySet]
    ([WorkflowEntityId]);
GO

-- Creating foreign key on [EmployeeEntityId] in table 'TaskEntitySet'
ALTER TABLE [dbo].[TaskEntitySet]
ADD CONSTRAINT [FK_EmployeeEntityTaskEntity]
    FOREIGN KEY ([EmployeeEntityId])
    REFERENCES [dbo].[EmployeeEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EmployeeEntityTaskEntity'
CREATE INDEX [IX_FK_EmployeeEntityTaskEntity]
ON [dbo].[TaskEntitySet]
    ([EmployeeEntityId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------